<template>
  <el-dialog custom-class="assets-picker" :title="title" :visible.sync="dialogVisible" width="35%">
    <el-transfer v-model="value" :data="data"></el-transfer>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="dialogVisible = true">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { getAssetList } from '@/api/asset'
export default {
  name: 'assets-picker',
  props: {
    title: {
      type: String,
      default: '资产选择'
    },
    visible: {
      type: Boolean,
      default: false
    }
  },
  created () {
    getAssetList().then(rows => {
      let data = []
      rows.forEach(row => {
        data.push({
          key: row.assetId,
          label: row.assetName
        })
      })
      this.data = data
    })
  },
  watch: {
    dialogVisible (val) {
      console.warn(val)
      this.$emit('update:visible', val)
    },
    visible (val) {
      this.dialogVisible = val
    }
  },
  data () {
    return {
      data: [],
      value: [],
      dialogVisible: true
    }
  }
}
</script>

<style lang="scss">
.assets-picker {
  /deep/.el-dialog__body {
    display: flex;
    align-items: center;
    justify-content: center;
  }
}
</style>
